#include "dominion.c"
#include "assert.h"
#include "stdio.h"
#include "rngs.c"

void checkEndTurn( struct gameState* );

int main(){
	int *cards = kingdomCards(7,8,9,10,11,12,13,14,15,16);
	struct gameState *state = newGame();
	
	initializeGame(4, cards, -1, state);
	
	for (int i = 0; i < 20; i++){
		checkEndTurn(state);
	}
	
	return 0;
}

void checkEndTurn(struct gameState *state){
	int lastPlayer = whoseTurn(state);
	endTurn(state);

	// Check that it's the proper player's turn
	// If the previous player was the last player, current player should be the 0th
	if( lastPlayer == (state->numPlayers - 1) && whoseTurn(state) != 0 ) {
		printf("Wrong player! Total players: %d. Current player: %d. Last player: %d\n", state->numPlayers, whoseTurn(state), lastPlayer);
		assert(0);
	} 
	// Else, the next player is the current player + 1
	if( (lastPlayer < state->numPlayers - 1) && (whoseTurn(state) != lastPlayer + 1) ) {
		printf("Wrong player! Total players: %d. Current player: %d. Last player: %d\n", state->numPlayers, whoseTurn(state), lastPlayer);
		assert(0);
	}
	// Make sure last player has no cards
	if ( state->handCount[lastPlayer] != 0 ) {
		printf("Last player still has cards! Last player: %d. Cards: %d\n", lastPlayer, state->handCount[lastPlayer]);		
		assert(0);
	}	
	// Make sure current player has 5 cards
	if( state->handCount[whoseTurn(state)] != 5 ){
		printf("Current player doesn't have 5 cards! Current player: %d. Cards: %d\n", whoseTurn(state), state->handCount[whoseTurn(state)]);		
		assert(0);
	}
}








